package com.siyoumi.app.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.siyoumi.app.entity.base.BookOrderBase;
import com.siyoumi.util.XDate;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDateTime;


@Data
@Accessors(chain = true)
@TableName(value = "t_book_order", schema = "wx_app_x")
public class BookOrder
        extends BookOrderBase {
    /**
     * 剩余分账金额
     */
    public BigDecimal matchShareSalesPriceLeft() {
        return getBorder_share_sales_price()
                .subtract(getBorder_share_sales_price_use());
    }

    /**
     * 剩余可锁定的金额
     */
    public BigDecimal matchPricePayTotalLockLeft() {
        return getBorder_price_spu()
                .subtract(getBorder_price_pay_total_lock());
    }

    public BigDecimal matchOriginalPrice() {
        return getBorder_price_sku()
                .add(getBorder_price_sku_append())
                .add(getBorder_price_set())
                .add(getBorder_price_set_append());
    }

    public BigDecimal matchSharePrice() {
        //分佣金额不算加价部分
        return getBorder_price_original()
                .subtract(getBorder_price_sku_append())
                .subtract(getBorder_price_set_append())
                ;
    }

    /**
     * 房费
     */
    public BigDecimal matchSpuPrice() {
        return getBorder_price_original()
                .subtract(getBorder_price_down_fun());
    }

    /**
     * 总金额
     */
    public BigDecimal matchFinalPrice() {
        return getBorder_price_spu()
                .add(getBorder_deposit_price());
    }

    /**
     * 支付总金额
     */
    public BigDecimal matchPaylPriceTotal() {
        return getBorder_price_pay()
                .add(getBorder_price_pay01());
    }

    /**
     * 剩余支付金额
     */
    public BigDecimal matchPayPriceLeft() {
        return getBorder_price_final()
                .subtract(getBorder_price_pay_total());
    }

    public String strEndDate(Boolean addContinue) {
        LocalDateTime endDate = endDate(addContinue);
        return XDate.toDateString(endDate.plusDays(1));
    }

    public LocalDateTime endDate(Boolean addContinue) {
        LocalDateTime endDate = getBorder_date_end_final();
        if (addContinue) {
            endDate = endDate.plusDays(getBorder_continue_day_total());
        }
        return endDate;
    }
}
